package tw.rescue.lib;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class DatastoreHelper {

	public static Key getKey(Object objectKey) {
		if (objectKey==null)
			return null;
		Key key;
		if (objectKey instanceof String)
			key = KeyFactory.stringToKey((String)objectKey);
		else if (objectKey instanceof Key)
			key = (Key)objectKey;
		else
			throw new IllegalArgumentException();
		return key;
	}

	public static String getKeyString(Object objectKey) {
		if (objectKey==null)
			return null;
		String keyString;
		if (objectKey instanceof String)
			keyString = (String)objectKey;
		else if (objectKey instanceof Key)
			keyString = KeyFactory.keyToString((Key)objectKey);
		else
			throw new IllegalArgumentException();
		return keyString;
	}
}
